package com.leetroll.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.leetroll.api.mapper.CommentMapper;
import com.leetroll.api.service.CommentService;
import com.leetroll.common.constant.SQLConstant;
import com.leetroll.common.entity.Comment;
import com.leetroll.common.vo.CommentVO;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CommentServiceImpl extends SuperServiceImpl<CommentMapper, Comment> implements CommentService {

    @Override
    public List<CommentVO> list(String rescType, Long rescId, Integer pageNumber, Integer pageSize) {
        return this.baseMapper.list(rescType, rescId, pageNumber, pageSize);
    }

    @Override
    @Cacheable(cacheNames = "commentCount")
    public Integer count(String rescType, Long rescId) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SQLConstant.RESC_TYPE, rescType);
        queryWrapper.eq(SQLConstant.RESC_ID, rescId);
        return this.list(queryWrapper).size();
    }
}
